package com.dingwei.superiordiary.adapter.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bobomee.android.mentions.edit.util.FormatRangeManager;
import com.bobomee.android.mentions.text.MentionTextView;
import com.bumptech.glide.Glide;
import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.app.MyApplication;
import com.dingwei.superiordiary.bean.MoreReplyBean;
import com.dingwei.superiordiary.parser.Parser;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.weight.MyGridView;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by lihao on 2018/1/8.
 */

public class CommentDetailsEvaluationListAdapter extends RecyclerArrayAdapter<MoreReplyBean.DataBean.SubBean> {

    private ReplyInterface replyInterface;

    public void setReplyInterface(ReplyInterface replyInterface) {
        this.replyInterface = replyInterface;
    }

    public CommentDetailsEvaluationListAdapter(Context context) {
        super(context);
    }
    private FormatRangeManager mRangeManager;
    private Parser mTagParser = new Parser();
    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new FindDetailsEvaluationListHolder(parent);
    }

    class FindDetailsEvaluationListHolder extends BaseViewHolder<MoreReplyBean.DataBean.SubBean> {


        @Bind(R.id.img_head)
        ImageView imgHead;
        @Bind(R.id.tv_nick_name)
        TextView tvNickName;
        @Bind(R.id.tv_level)
        TextView tvLevel;
        @Bind(R.id.tv_time)
        TextView tvTime;
        @Bind(R.id.tv_floor)
        TextView tvFloor;
        @Bind(R.id.tv_content)
        MentionTextView tvContent;
        @Bind(R.id.gridview)
        MyGridView gridview;
        @Bind(R.id.tv_evaluation_num)
        TextView tvEvaluationNum;
        @Bind(R.id.img_like)
        ImageView imgLike;
        @Bind(R.id.tv_like_num)
        TextView tvLikeNum;
        @Bind(R.id.like_layout)
        LinearLayout likeLayout;
        @Bind(R.id.ic_tread)
        ImageView icTread;
        @Bind(R.id.tv_tread_num)
        TextView tvTreadNum;
        @Bind(R.id.tread_layout)
        LinearLayout treadLayout;

        public FindDetailsEvaluationListHolder(ViewGroup parent) {
            super(parent, R.layout.item_comment_details_evaluation_list);
            ButterKnife.bind(this, itemView);
            mRangeManager = new FormatRangeManager();
            tvContent.setMovementMethod(new LinkMovementMethod());
            tvContent.setParserConverter(mTagParser);


        }


        @Override
        public void setData(final MoreReplyBean.DataBean.SubBean data) {
            super.setData(data);
            Glide.with(BaseActivity.context)
                    .load(data.portrait)
                    .apply(MyApplication.headOptions)
                    .into(imgHead);
            tvNickName.setText(data.nickname);
            tvTime.setText(data.addtime);
            tvLevel.setText("LV." + data.level);
            String s = data.content.replaceAll("'>", "'>@");
            tvContent.setText(s);
            if (data.is_liked == 1) {
                imgLike.setImageResource(R.mipmap.ic_liked);
            } else {
                imgLike.setImageResource(R.mipmap.ic_like);
            }
            tvLikeNum.setText(data.likes);
            tvTreadNum.setText(data.trample);

            if (!TextUtils.isEmpty(data.floor)){
                tvFloor.setText(data.floor+"楼");
                tvFloor.setVisibility(View.VISIBLE);
            }else {
                tvFloor.setVisibility(View.GONE);
            }


            tvEvaluationNum.setVisibility(View.GONE);

            likeLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (replyInterface != null) {
                        replyInterface.likes(getDataPosition());
                    }
                }
            });

            treadLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (replyInterface != null) {
                        replyInterface.cai(getDataPosition());
                    }
                }
            });
            imgHead.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (replyInterface != null) {
                        replyInterface.subUser(data.consumer_id);
                    }
                }
            });

        }
    }


    public interface ReplyInterface {

        void likes(int position);


        void cai(int position);

        void subUser(String user_id);

        void more(int position);
    }
}
